package com.practice.tetris.ui;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

/**
 * Author: Zhouyue
 * Date: 2015/6/7.
 */
public abstract class Layer {
    /**
     *图片素材存储路径
     */
    private static URL IMG_URL = Layer.class.getResource("/window/window.png");
    /**
     * 图片素材
     */
    private static Image IMG_WINDOW = new ImageIcon(IMG_URL).getImage();
    /**
     * 图片素材角宽度
     */
    private static final int CORNER = 7;
    /**
     * 图片素材宽度
     */
    private static int IMG_WIDTH = IMG_WINDOW.getWidth(null);
    /**
     * 图片素材高度
     */
    private static int IMG_HEIGHT = IMG_WINDOW.getHeight(null);
    /**
     * 窗口左上角横坐标
     */
    protected int x;
    /**
     * 窗口左上角纵坐标
     */
    protected int y;
    /**
     * 窗口宽度
     */
    protected int width;
    /**
     * 窗口高度
     */
    protected int height;
    /**
     * 内边距
     */
    protected static final int PADDING = 16;

    public Layer(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }

    protected void createLayer(Graphics g) {
        //左上角
        g.drawImage(IMG_WINDOW, x, y, x + CORNER, y + CORNER, 0, 0 ,CORNER, CORNER, null);
        //上边框
        g.drawImage(IMG_WINDOW, x + CORNER, y, x + width - CORNER, y + CORNER, CORNER, 0, IMG_WIDTH - CORNER, CORNER, null);
        //右上角
        g.drawImage(IMG_WINDOW, x + width - CORNER, y, x + width, y + CORNER, IMG_WIDTH - CORNER, 0, IMG_WIDTH, CORNER, null);
        //右边框
        g.drawImage(IMG_WINDOW, x + width - CORNER, y + CORNER, x + width, y + height - CORNER, IMG_WIDTH - CORNER, CORNER, IMG_WIDTH, IMG_HEIGHT - CORNER, null);
        //右下角
        g.drawImage(IMG_WINDOW, x + width - CORNER, y + height - CORNER, x + width, y + height, IMG_WIDTH - CORNER, IMG_HEIGHT - CORNER, IMG_WIDTH, IMG_HEIGHT, null);
        //下边框
        g.drawImage(IMG_WINDOW, x + CORNER, y + height - CORNER, x + width - CORNER, y + height, CORNER, IMG_HEIGHT - CORNER, IMG_WIDTH - CORNER, IMG_HEIGHT, null);
        //左下角
        g.drawImage(IMG_WINDOW, x, y + height - CORNER, x + CORNER, y + height, 0, IMG_HEIGHT - CORNER, CORNER, IMG_HEIGHT, null);
        //左边框
        g.drawImage(IMG_WINDOW, x, y + CORNER, x + CORNER, y + height - CORNER, 0, CORNER, CORNER, IMG_HEIGHT - CORNER, null);
        //窗体内部
        g.drawImage(IMG_WINDOW, x + CORNER, y + CORNER, x + width - CORNER, y + height - CORNER, CORNER, CORNER, IMG_WIDTH - CORNER, IMG_HEIGHT - CORNER, null);
    }

    public abstract void paint(Graphics g);
}
